//
//  CCYTabbarViewController.swift
//  03.微博
//
//  Created by 蔡承毅 on 16/9/16.
//  Copyright © 2016年 IOS. All rights reserved.
//

import UIKit

class CCYTabbarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let newTabBar = CCYMainTabBar()
        
        self.setValue(newTabBar, forKey: "tabBar")
        // 2.传递闭包👇                1.定义闭包👇
        newTabBar.composeClosure = { () -> () in
            print("闭包被点击了")
        }

        addChildViewController()
    }
    
    private func addChildViewController() {
//        tabBar.tintColor = UIColor.brown
        
        // 首页
        let homeTableVC = CCYHomeViewController()
        addChildViewController(controller: homeTableVC, title: "首页", imageName: "tabbar_home")
        
        // 消息
        let messageTableVC = CCYMessageViewController()
        addChildViewController(controller: messageTableVC, title: "消息", imageName: "tabbar_message_center")
        
        // 发现
        let discoverTableVc = CCYDiscoverViewController()
        addChildViewController(controller: discoverTableVc, title: "发现", imageName: "tabbar_discover")
        
        // 我
        let profileTableVC = CCYProfileViewController()
        addChildViewController(controller: profileTableVC, title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(controller: UIViewController, title: String, imageName: String) {
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
        let profileNav = UINavigationController(rootViewController: controller)
        addChildViewController(profileNav)
        
    }

}
